import java.util.List;
import java.util.ArrayList;
import java.io.BufferedReader;

public class PrimeNumbers {
	private final int firstPrimeNumber = 2;
	
	public static List<Integer> getPrimeNumbers(int bound) {
		List<Integer> primeNumbersList = new ArrayList<Integer>();
		boolean notPrimeNumber;
		
		if (bound <= 0){
			return null;
		}
		
		for (int currentNumber = firstPrimeNumber; currentNumber <= bound; ++currentNumber) {
			notPrimeNumber = false;
			
			for (int divizer = firstPrimeNumber; divizer < currentNumber; ++divizer) {
				if (currentNumber % divizer != 0) {
					notPrimeNumber = true;
					break;
				}
			}
			
			if (!notPrimeNumber) {
				primeNumbersList.add(currentNumber);
			}			
		}
		
		return primeNumbersList;
	}
	
	public static void main(String[] args) {
		int number;
		List<Integer> primeNumbers;
		
		System.out.print("Enter number: ");
		
		try {
			BufferedReader consoleReader = new BufferedReader(new java.io.InputStreamReader(System.in));
			number = new Integer(consoleReader.readLine()).intValue();
			primeNumbers = PrimeNumbers.getPrimeNumbers(number);
		} catch (java.lang.NumberFormatException  ex) {
			System.out.println("Error! Wrong number.");
			return;
		} catch (java.io.IOException ex) {
			System.out.println("Caught IO error!");
			System.out.println(ex);
			return;
		}
		
		if (primeNumbers == null) {
			System.out.println("Error! Number must be more than 0.");
		} else {
			System.out.println("List of prime numbers from 1 to " + number);
			
			for (Integer prime : primeNumbers) {
				System.out.print(prime + " ");
			}
		}
	}
}